package com.derbysoft.ota.application.translator.rs;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.application.util.ParagraphTypes;
import com.derbysoft.ota.interfaces.protocol._2009a.RoomTypeType;
import com.derbysoft.ota.interfaces.protocol._2009a.RoomTypeType.Occupancy;
import com.derbysoft.remote.dswitch.generic.constants.AgeQualifyingType;
import com.derbysoft.remote.dswitch.generic.constants.SmokingType;
import com.derbysoft.remote.dswitch.hotel.constants.CompositeType;
import com.derbysoft.remote.dswitch.hotel.dto.RoomTypeDTO;

public class RoomTypeTranslator implements Translator<RoomTypeDTO, RoomTypeType> {

	public RoomTypeType translate(RoomTypeDTO source) {
		RoomTypeType dest = new RoomTypeType();
		dest.setRoomTypeCode(source.getCode());
		dest.setRoomType(source.getName());
		dest.setRoomDescription(ParagraphTypes.of(source.getDescription()));
		if(source.getFloor() != null){
			dest.setFloor(source.getFloor());
		}
		if(CompositeType.COMPOSITE == source.getCompositeType()) {
			dest.setComposite(true);
		} else if (CompositeType.NONCOMPOSITE == source.getCompositeType()) {
			dest.setComposite(false);
		}
		
		if(SmokingType.NONSMOKING == source.getSmokingType()){
			dest.setNonSmoking(true);
		} else if (SmokingType.SMOKING == source.getSmokingType()) {
			dest.setNonSmoking(false);
		}
		
		dest.setSizeMeasurement(source.getSizeMeasurement());
		if(source.getAdultCount() != null) {
			dest.getOccupancy().add(adult(source));
		}
		if(source.getChildCount() != null) {
			dest.getOccupancy().add(child(source));
		}
		return dest; 
	}

	private Occupancy child(RoomTypeDTO source) {
		Occupancy occupancy = new Occupancy();
		occupancy.setAgeQualifyingCode(String.valueOf(AgeQualifyingType.CHILD.getCode()));
		occupancy.setMaxOccupancy(source.getChildCount());
		return occupancy;
	}

	private Occupancy adult(RoomTypeDTO source) {
		Occupancy occupancy = new Occupancy();
		occupancy.setAgeQualifyingCode(String.valueOf(AgeQualifyingType.ADULT.getCode()));
		occupancy.setMaxOccupancy(source.getAdultCount());
		return occupancy;
	}

	

}
